Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable additional code checks #29858

Closed
wants to merge 2 commits into from

Conversation

fwyzard
Copy link
Contributor

@fwyzard fwyzard commented May 16, 2020

performance-faster-string-find:

Optimize calls to std::string::find() and friends when the needle passed is a single character string literal.

performance-for-range-copy:

Finds C++11 for ranges where the loop variable is copied in each iteration but it would suffice to obtain it by const reference.

performance-implicit-conversion-in-loop:

This warning appears in a range-based loop with a loop variable of const ref type where the type of the variable does not match the one returned by the iterator. This means that an implicit conversion happens, which can for example result in expensive deep copies.

performance-inefficient-algorithm:

Warns on inefficient use of STL algorithms on associative containers.

performance-inefficient-vector-operation:

Finds possible inefficient std::vector operations (e.g. push_back, emplace_back) that may cause unnecessary memory reallocations.

performance-move-const-arg:

Warn about inefficient use of std::move, and suggest a fix that removes it.

performance-unnecessary-copy-initialization:

Finds local variable declarations that are initialized using the copy constructor of a non-trivially-copyable type, where it would suffice to obtain a const reference.

performance-unnecessary-value-param:

Flags value parameter declarations of expensive to copy types that are copied for each invocation, where it would suffice to pass them by const reference.

modernize-make-unique:

Finds the creation of std::unique_ptr objects explicitly calling a new expression, and replaces it with a call to std::make_unique.

modernize-loop-convert:

This check converts for(...; ...; ...) loops to use the new range-based loops in C++11.
The MinConfidence option was already set to "reasonable".

modernize-use-auto:

Use the auto type specifier for variable declarations to improve code readability and maintainability.
The MinTypeNameLength option is set to 16 characters.

modernize-use-emplace:

The check flags insertions to an STL-style container done by calling the push_back method with an explicitly-constructed temporary of the container element type. In this case, the corresponding emplace_back method results in less verbose and potentially more efficient code.

@cmsbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

@fwyzard
Copy link
Contributor Author

fwyzard commented May 16, 2020

This was spurred by the review of the L1 track trigger code, where some of these checks should really be automated.

I assume some checks will be more controversial than others, and/or run into false positives in our code base, but let's start having a look ...

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29858/15415

  • This PR adds an extra 12KB to repository

@cmsbuild
Copy link
Contributor

A new Pull Request was created by @fwyzard (Andrea Bocci) for master.

It involves the following packages:

.clang-tidy

@makortel, @smuzaffar, @cmsbuild, @Dr15Jones can you please review it and eventually sign? Thanks.
@makortel this is something you requested to watch as well.
@silviodonato, @dpiparo you are the release manager for this.

cms-bot commands are listed here

@fwyzard
Copy link
Contributor Author

fwyzard commented May 16, 2020

@smuzaffar is there a way to make the bot run the code checks using the modified .clang-tidy file ?

@fwyzard fwyzard force-pushed the enable_additional_code_checks branch from 0183239 to c2dcc12 Compare May 16, 2020 10:52
@fwyzard fwyzard changed the title Enable addition code checks Enable additional code checks May 16, 2020
@cmsbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

performance-faster-string-find:
  Optimize calls to std::string::find() and friends when the needle passed is
  a single character string literal.

performance-for-range-copy:
  Finds C++11 for ranges where the loop variable is copied in each iteration
  but it would suffice to obtain it by const reference.

performance-implicit-conversion-in-loop:
  This warning appears in a range-based loop with a loop variable of const ref
  type where the type of the variable does not match the one returned by the
  iterator. This means that an implicit conversion happens, which can for
  example result in expensive deep copies.

performance-inefficient-algorithm:
  Warns on inefficient use of STL algorithms on associative containers.

performance-inefficient-vector-operation:
  Finds possible inefficient std::vector operations (e.g. push_back, emplace_back)
  that may cause unnecessary memory reallocations.

performance-move-const-arg:
  Warn about inefficient use of std::move, and suggest a fix that removes it.

performance-unnecessary-copy-initialization:
  Finds local variable declarations that are initialized using the copy
  constructor of a non-trivially-copyable type, where it would suffice to
  obtain a const reference.

performance-unnecessary-value-param:
  Flags value parameter declarations of expensive to copy types that are copied
  for each invocation, where it would suffice to pass them by const reference.

modernize-make-unique:
  Finds the creation of std::unique_ptr objects explicitly calling a new
  expression, and replaces it with a call to std::make_unique.

modernize-loop-convert:
  This check converts for(...; ...; ...) loops to use the new range-based loops
  in C++11.
  The MinConfidence option was already set to "reasonable".

modernize-use-auto:
  Use the auto type specifier for variable declarations to improve code
  readability and maintainability.
  The MinTypeNameLength option is set to 16 characters.

modernize-use-emplace:
  The check flags insertions to an STL-style container done by calling the
  push_back method with an explicitly-constructed temporary of the container
  element type. In this case, the corresponding emplace_back method results
  in less verbose and potentially more efficient code.
@fwyzard fwyzard force-pushed the enable_additional_code_checks branch from c2dcc12 to 5a6dc7f Compare May 16, 2020 10:53
@cmsbuild
Copy link
Contributor

The code-checks are being triggered in jenkins.

@cmsbuild
Copy link
Contributor

+code-checks

Logs: https://cmssdt.cern.ch/SDT/code-checks/cms-sw-PR-29858/15417

  • This PR adds an extra 16KB to repository

@cmsbuild
Copy link
Contributor

Pull request #29858 was updated. @makortel, @smuzaffar, @cmsbuild, @Dr15Jones can you please check and sign again.

@slava77
Copy link
Contributor

slava77 commented May 16, 2020

I assume some checks will be more controversial than others, and/or run into false positives in our code base, but let's start having a look ...

as in the past, it may be more effective to make a PR with code changes for some selected "representative" package or subsystem so that others could comment.

@fwyzard
Copy link
Contributor Author

fwyzard commented May 16, 2020

Indeed - clang-tidy has been working on it for a while now...

@fwyzard
Copy link
Contributor Author

fwyzard commented May 17, 2020

#29863 shows all the code changes from these additions, generated with

scram b -j`nproc` llvm-ccdb
cat $CMSSW_BASE/compile_commands.json | grep '"file"' | cut -d'"' -f4 | xargs $(scram tool tag llvm LLVM_BASE)/share/clang/run-clang-tidy.py -header-filter "$CMSSW_BASE/src/.*" -j`nproc` -fix -format

I can generate smaller change sets (e.g. for a single package or subsystem, or only some of the options) if needed.

@makortel
Copy link
Contributor

Thanks @fwyzard, by quick look on random files in #29863 the new options look pretty good to me.

For deployment I would nevertheless consider to split the set of options into two: straightforward ones, and the ones where the output is more subjective. To me modernize-loop-convert and modernize-use-auto are in the latter category (not all loops that by eye could be converted to range-for are converted, and the MinTypeNameLength may rise some discussion). The "straightforward options" could be deployed "immediately" (expecting trivial review), and the less-straightforward ones in a second pass (with possibly less trivial review).

We could anyway discuss this in the next core software meeting.

@fwyzard
Copy link
Contributor Author

fwyzard commented May 17, 2020

We could anyway discuss this in the next core software meeting.

I agree... also, the PR as is now is pretty huge, I might split the commits by option and/or by package.

@makortel
Copy link
Contributor

We could anyway discuss this in the next core software meeting.

I agree... also, the PR as is now is pretty huge, I might split the commits by option and/or by package.

Right, at least for deployment it needs to be split up (perhaps with the aid of @cmsbuild? at least for the "straightforward options").

@kpedro88
Copy link
Contributor

For posterity: in a future update, it would also be nice to include https://reviews.llvm.org/D54943 (const correctness, still in development) once it's finished, approved, and validated/stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants